package org.fuyd.designpattern;

import com.google.common.collect.Maps;

import java.util.Map;

/**
 * Created by Jason on 2015/10/23.
 */
public class App2 {

    /**
     * 字典
     */
    private static String[] chars = new String[]{
            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
            "A", "B", "C", "D", "E", "F", "G",
            "H", "I", "J", "K", "L", "M", "N",
            "O", "P", "Q", "R", "S", "T",
            "U", "V", "W", "X", "Y", "Z"
    };

    public static void main(String[] args) {
        String str = "FELH2B1HJ";
        String[] cs = str.split("");

        Map<Integer, String> map = Maps.newHashMap();
        for (int i = 1; i < cs.length; i++) {
            String s = cs[i];
            System.out.print(s + "   ");

            int j = 0;
            while (!chars[j].equals(s)) {
                j++;
            }
            System.out.print(j + "   ");
            System.out.println();

            map.put(i, buwei(ten2two(j), 5));
        }

        String s = "";
        for (int i = 7; i >0; i--) {
            s = s+map.get(i);
        }

        System.out.println(two2tenl(s));

        String b = buwei(map.get(9),5) + buwei(map.get(8), 5);
        System.out.println(two2tenl(b));

        long result = Long.valueOf(String.valueOf(two2tenl(s))+ String.valueOf(two2tenl(b)));

        System.out.println(result);
    }

    public static String buwei(String str, int length) {
        if (str.length() > length) {
            return str;
        }

        int i = length - str.length();

        for (int j = 0; j < i; j++) {
            str = "0".concat(str);
        }
        return str;
    }

    /**
     * 十进制转二进制
     *
     * @param i
     * @return
     */
    public static String ten2two(int i) {
        return Integer.toBinaryString(i);
    }

    /**
     * 二进制转十进制
     *
     * @param str
     * @return
     */
    public static int two2teni(String str) {
        return Integer.valueOf(str, 2);
    }

    /**
     * 十进制转二进制
     *
     * @param l
     * @return
     */
    public static String ten2two(long l) {
        return Long.toBinaryString(l);
    }

    /**
     * 二进制转十进制
     *
     * @param str
     * @return
     */
    public static long two2tenl(String str) {
        return Long.valueOf(str, 2);
    }

    /**
     * 十六进制转二进制
     *
     * @param l
     * @return
     */
    public static String sixteen2two(long l) {
        return Long.toBinaryString(l);
    }

    /**
     * 十六进制转二进制
     *
     * @param i
     * @return
     */
    public static String sixteen2two(int i) {
        return Integer.toBinaryString(i);
    }
}
